package com.jy.tdata.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommonResult<T> implements Serializable {
    private Integer code;
    private String message;
    private T data;

    public static CommonResult success() {
        CommonResult result = new CommonResult();
        result.setCode(200);
        result.setMessage("成功");
        return result;
    }

    public static <T> CommonResult<T> success(T data) {
        CommonResult<T> result = new CommonResult<T>();
        result.setData(data);
        result.setCode(200);
        result.setMessage("成功");
        return result;
    }
    public static CommonResult ok(CommonResult commonResult){
        CommonResult result =new CommonResult();
        result.setData(commonResult);
        result.setCode(200);
        result.setMessage("成功");
        return result;
    }

    public static CommonResult error(Integer code, String msg) {
        CommonResult result = new CommonResult();
        result.setCode(code);
        result.setMessage(msg);
        return result;
    }
    public static CommonResult error(String msg) {
        CommonResult result = new CommonResult();
        result.setMessage(msg);
        return result;
    }
}
